package com.kumarn.android.imagesave.full;

import java.io.File;

import com.kumarn.android.imagesave.full.manager.DirectoryManager;
import com.kumarn.android.imagesave.full.view.ScaleImageView;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class GoodsScaleImageActivity extends Activity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.goods_scaleimage);

		Intent i = getIntent();
		String imgName = i.getStringExtra("img");
		String title = i.getStringExtra("title");

		TextView titleText = (TextView)findViewById(R.id.title_name);
		titleText.setText(title);

		String filepath = (new DirectoryManager()).getImageDir().getPath() + "/" + imgName + ".jpg";
		File file = new File(filepath);

		Bitmap bmp = null;
		//ファイルがあれば取得
		if(file.exists()){
			//画像保存PathからBitmap取得
			bmp = BitmapFactory.decodeFile(filepath);
		//無ければnoImage画像をセット
		}else{
			Resources res = this.getResources();
			bmp = BitmapFactory.decodeResource(res, R.drawable.noimage);
		}

		ScaleImageView siv = (ScaleImageView)findViewById(R.id.scaleimage);
		siv.setImageBitmap(bmp);

		ImageView closeButton = (ImageView)findViewById(R.id.close_button);
		closeButton.setOnClickListener(closeButton_OnclickListener);
	}

	OnClickListener closeButton_OnclickListener = new OnClickListener() {
		public void onClick(View v) {
			finish();
		}
	};
}